package mlz.h_stringBuilder;

//String、StringBuilder、StringBuffer的效率对比
public class BuilderDemo02 {
    public static void main(String[] args) {
        String s1 = "";
        StringBuffer s2 = new StringBuffer();
        StringBuilder s3 = new StringBuilder();

        //获取当前系统时间
        long time1 = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            s1 += i;
        }
        long time2 = System.currentTimeMillis();
        System.out.println(time2 - time1);//4677 4768

        for (int i = 0; i < 100000; i++) {
            s2.append(i);
        }
        long time3 = System.currentTimeMillis();
        System.out.println(time3 - time2);//8

        for (int i = 0; i < 100000; i++) {
            s3.append(i);
        }
        long time4 = System.currentTimeMillis();
        System.out.println(time4 - time3);//5
    }
}
